package com.example.bbsbe.Repository;

import com.example.bbsbe.entity.user;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface UserRepository extends JpaRepository<user, Long> {
    user findIdByName(String name) ;

    Optional<user> findByNameAndPsw(String name, String password);
    boolean existsByName(String username);

    user findByName(String username);
    // 更新用户等级
    @Modifying
    @Query("UPDATE user u SET u.level = u.level + :increment WHERE u.id = :userId")
    void incrementLevel(@Param("userId") String userId, @Param("increment") int increment);
}
